package com.sw.paisong.service.impl;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sw.paisong.dao.PosRecordDao;
import com.sw.paisong.dao.StaffDao;
import com.sw.paisong.entity.PosRecordEntity;
import com.sw.paisong.entity.StaffEntity;
import com.sw.paisong.service.PosService;
import com.sw.paisong.vo.JsonVO;
import com.sw.paisong.vo.mob.ReportPosFormVO;

@Service
public class PosServiceImpl implements PosService {
	private static final Logger logger = LoggerFactory.getLogger(PosServiceImpl.class);

	@Autowired
	StaffDao staffDao;

	@Autowired
	PosRecordDao posRecordDao;

	@Override
	public JsonVO<Object> reportPos(ReportPosFormVO reportPosForm) {
		JsonVO<Object> resJson = new JsonVO<Object>();
		StaffEntity staffEntity = staffDao.findOne(reportPosForm.getToken());
		if (staffEntity == null) {
			resJson.setSuccess(false);
			resJson.setMessage("cant find staff");
		} else {
			PosRecordEntity posRecord = new PosRecordEntity();
			posRecord.setStaff(staffEntity);
			posRecord.setLat(reportPosForm.getLat());
			posRecord.setLng(reportPosForm.getLng());
			posRecord.setRecordTime(new Date());
			posRecordDao.save(posRecord);
			resJson.setSuccess(true);
			resJson.setMessage("数据提交成功");
		}
		return resJson;
	}
}
